﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：SYS_LOG实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class SYS_LOG
    {
        private int? m_dec_i_kid;

        private int m_dec_id;

        private DateTime? m_DT_d_caozuosj;

        private string m_o_s_rizhinr;

        private string m_str_s_biaoming;

        private string m_str_s_caozuolx;

        private string m_str_s_caozuor;

        private string m_str_s_ip;

        private string m_str_s_laihanbh;

        private string m_str_s_suoshumk;

        private string m_str_s_yewulx;

        private string m_str_s_yonghuh;

        private string m_str_s_zhujian;

        /// <summary>
        ///     自增量
        /// </summary>
        public int ID
        {
            get { return m_dec_id; }
            set { m_dec_id = value; }
        }

        /// <summary>
        ///     操作人
        /// </summary>
        public string S_CAOZUOR
        {
            get { return m_str_s_caozuor; }
            set { m_str_s_caozuor = value; }
        }

        /// <summary>
        ///     操作日期
        /// </summary>
        public DateTime? D_CAOZUOSJ
        {
            get { return m_DT_d_caozuosj; }
            set { m_DT_d_caozuosj = value; }
        }

        /// <summary>
        ///     操作类型
        /// </summary>
        public string S_CAOZUOLX
        {
            get { return m_str_s_caozuolx; }
            set { m_str_s_caozuolx = value; }
        }

        /// <summary>
        ///     业务类型
        /// </summary>
        public string S_YEWULX
        {
            get { return m_str_s_yewulx; }
            set { m_str_s_yewulx = value; }
        }

        /// <summary>
        ///     所属模块
        /// </summary>
        public string S_SUOSHUMK
        {
            get { return m_str_s_suoshumk; }
            set { m_str_s_suoshumk = value; }
        }

        /// <summary>
        ///     表名
        /// </summary>
        public string S_BIAOMING
        {
            get { return m_str_s_biaoming; }
            set { m_str_s_biaoming = value; }
        }

        /// <summary>
        ///     主键
        /// </summary>
        public string S_ZHUJIAN
        {
            get { return m_str_s_zhujian; }
            set { m_str_s_zhujian = value; }
        }

        /// <summary>
        ///     IP地址
        /// </summary>
        public string S_IP
        {
            get { return m_str_s_ip; }
            set { m_str_s_ip = value; }
        }

        /// <summary>
        ///     用户号
        /// </summary>
        public string S_YONGHUH
        {
            get { return m_str_s_yonghuh; }
            set { m_str_s_yonghuh = value; }
        }

        /// <summary>
        ///     来函编号
        /// </summary>
        public string S_LAIHANBH
        {
            get { return m_str_s_laihanbh; }
            set { m_str_s_laihanbh = value; }
        }

        /// <summary>
        ///     流程编号
        /// </summary>
        public int? I_KID
        {
            get { return m_dec_i_kid; }
            set { m_dec_i_kid = value; }
        }

        /// <summary>
        ///     日志内容
        /// </summary>
        public string S_RIZHINR
        {
            get { return m_o_s_rizhinr; }
            set { m_o_s_rizhinr = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class SYS_LOGProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public SYS_LOGProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据SYS_LOG实体添加或者修改SYS_LOG信息
        /// </summary>
        public bool InsertOrUpdate(SYS_LOG SYS_LOG, OracleTransaction Transaction)
        {
            if (SYS_LOG.ID == 0)
                InsertSYS_LOG(SYS_LOG, Transaction);
            else
                UpdateSYS_LOG(SYS_LOG, Transaction);
            return SYS_LOG.ID == 0 ? false : true;
        }

        /// <summary>
        ///     根据SYS_LOG实体添加或修改SYS_LOG信息
        /// </summary>
        public bool InsertOrUpdate(SYS_LOG SYS_LOG)
        {
            return InsertOrUpdate(SYS_LOG, null);
        }


        /// <summary>
        ///     根据SYS_LOG主键删除SYS_LOG信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteSYS_LOG(int ID, OracleTransaction Transaction)
        {
            var spName = "CS_DelSYS_LOG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据SYS_LOG主键删除SYS_LOG信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteSYS_LOG(int ID)
        {
            return DeleteSYS_LOG(ID, null);
        }

        /// <summary>
        ///     根据条件删除SYS_LOG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteSYS_LOGsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelSYS_LOGsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除SYS_LOG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteSYS_LOGsDynamic(string WhereClause)
        {
            return DeleteSYS_LOGsDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据SYS_LOG主键选择SYS_LOG信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>SYS_LOG信息</returns>
        public SYS_LOG SelectSYS_LOG(int ID, OracleTransaction Transaction)
        {
            var spName = "CS_SelSYS_LOG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var SYS_LOG = PopulateSYS_LOG(rd);
                rd.Close();
                return SYS_LOG;
            }
            return null;
        }

        /// <summary>
        ///     根据SYS_LOG主键选择SYS_LOG信息
        /// </summary>
        /// <returns>SYS_LOG信息</returns>
        public SYS_LOG SelectSYS_LOG(int ID)
        {
            return SelectSYS_LOG(ID, null);
        }

        /// <summary>
        ///     选择所有SYS_LOG信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有SYS_LOG信息</returns>
        public DataTable SelectSYS_LOGsAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelSYS_LOGsAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有SYS_LOG信息
        /// </summary>
        /// <returns>所有SYS_LOG信息</returns>
        public DataTable SelectSYS_LOGsAll()
        {
            return SelectSYS_LOGsAll(null);
        }

        /// <summary>
        ///     根据条件选择SYS_LOG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>SYS_LOG信息</returns>
        public DataTable SelectSYS_LOGsDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelSYS_LOGsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择SYS_LOG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>SYS_LOG信息</returns>
        public DataTable SelectSYS_LOGsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectSYS_LOGsDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择SYS_LOG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>SYS_LOG信息</returns>
        public DataTable SelectSYS_LOGsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelSYS_LOGsDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择SYS_LOG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>SYS_LOG信息</returns>
        public DataTable SelectSYS_LOGsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectSYS_LOGsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新SYS_LOG字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateSYS_LOGsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdSYS_LOGDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新SYS_LOG字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateSYS_LOGsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateSYS_LOGsDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertSYS_LOG(SYS_LOG SYS_LOG, OracleTransaction Transaction)
        {
            var spName = "CS_InsSYS_LOG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = SYS_LOG.S_CAOZUOR;
            storedParams[1].Value = SYS_LOG.D_CAOZUOSJ;
            storedParams[2].Value = SYS_LOG.S_CAOZUOLX;
            storedParams[3].Value = SYS_LOG.S_YEWULX;
            storedParams[4].Value = SYS_LOG.S_SUOSHUMK;
            storedParams[5].Value = SYS_LOG.S_BIAOMING;
            storedParams[6].Value = SYS_LOG.S_ZHUJIAN;
            storedParams[7].Value = SYS_LOG.S_IP;
            storedParams[8].Value = SYS_LOG.S_YONGHUH;
            storedParams[9].Value = SYS_LOG.S_LAIHANBH;
            storedParams[10].Value = SYS_LOG.I_KID;
            storedParams[11].Value = SYS_LOG.S_RIZHINR;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            SYS_LOG.ID = Convert.ToInt32(storedParams[12].Value);
            return result;
        }

        private bool UpdateSYS_LOG(SYS_LOG SYS_LOG, OracleTransaction Transaction)
        {
            var spName = "CS_UpdSYS_LOG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = SYS_LOG.S_CAOZUOR;
            storedParams[1].Value = SYS_LOG.D_CAOZUOSJ;
            storedParams[2].Value = SYS_LOG.S_CAOZUOLX;
            storedParams[3].Value = SYS_LOG.S_YEWULX;
            storedParams[4].Value = SYS_LOG.S_SUOSHUMK;
            storedParams[5].Value = SYS_LOG.S_BIAOMING;
            storedParams[6].Value = SYS_LOG.S_ZHUJIAN;
            storedParams[7].Value = SYS_LOG.S_IP;
            storedParams[8].Value = SYS_LOG.S_YONGHUH;
            storedParams[9].Value = SYS_LOG.S_LAIHANBH;
            storedParams[10].Value = SYS_LOG.I_KID;
            storedParams[11].Value = SYS_LOG.S_RIZHINR;
            storedParams[12].Value = SYS_LOG.ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private SYS_LOG PopulateSYS_LOG(IDataReader dr)
        {
            var SYS_LOG = new SYS_LOG();
            SYS_LOG.ID = dr["ID"] == DBNull.Value ? 0 : (int) dr["ID"];
            SYS_LOG.S_CAOZUOR = dr["S_CAOZUOR"] == DBNull.Value ? null : (string) dr["S_CAOZUOR"];
            SYS_LOG.D_CAOZUOSJ = dr["D_CAOZUOSJ"] == DBNull.Value ? null : (DateTime?) dr["D_CAOZUOSJ"];
            SYS_LOG.S_CAOZUOLX = dr["S_CAOZUOLX"] == DBNull.Value ? null : (string) dr["S_CAOZUOLX"];
            SYS_LOG.S_YEWULX = dr["S_YEWULX"] == DBNull.Value ? null : (string) dr["S_YEWULX"];
            SYS_LOG.S_SUOSHUMK = dr["S_SUOSHUMK"] == DBNull.Value ? null : (string) dr["S_SUOSHUMK"];
            SYS_LOG.S_BIAOMING = dr["S_BIAOMING"] == DBNull.Value ? null : (string) dr["S_BIAOMING"];
            SYS_LOG.S_ZHUJIAN = dr["S_ZHUJIAN"] == DBNull.Value ? null : (string) dr["S_ZHUJIAN"];
            SYS_LOG.S_IP = dr["S_IP"] == DBNull.Value ? null : (string) dr["S_IP"];
            SYS_LOG.S_YONGHUH = dr["S_YONGHUH"] == DBNull.Value ? null : (string) dr["S_YONGHUH"];
            SYS_LOG.S_LAIHANBH = dr["S_LAIHANBH"] == DBNull.Value ? null : (string) dr["S_LAIHANBH"];
            SYS_LOG.I_KID = dr["I_KID"] == DBNull.Value ? null : (int?) dr["I_KID"];
            SYS_LOG.S_RIZHINR = dr["S_RIZHINR"] == DBNull.Value ? null : (string) dr["S_RIZHINR"];
            return SYS_LOG;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion